<?php

namespace app\admin\model;

use think\Model;

class User extends Model
{
    public function comments()
    {
        return $this->hasMany('AuthGroupAccess', 'uid');
    }

    //根据用户id获取用户和角色信息
    public static function getUserInfoRole($userId = null)
    {
        //空
        if (empty($userId)) {
            $res = model('user')->alias('a')->join('tbl_auth_group_access b', 'a.id= b.uid')
                ->join('tbl_auth_group c', 'b.group_id= c.id')
                ->field('a.id id,a.username username,a.phone_number phone_number,a.email email,
                a.gender gender,a.status status,a.update_time update_time,a.alias_name alias_name,
                b.uid uid,b.group_id group_id,c.id cid,
                c.title title,c.rules rules')
                ->select();
        } else {
            $res = model('user')->alias('a')->join('tbl_auth_group_access b', 'a.id= b.uid')
                ->join('tbl_auth_group c', 'b.group_id= c.id')
                ->field('a.id id,a.username username,a.phone_number phone_number,a.email email,
                a.gender gender,a.status status,a.update_time update_time,a.alias_name alias_name,
                b.uid uid,b.group_id group_id,c.id cid,
                c.title title,c.rules rules')
                ->where('a.id', '=', $userId)->select();
        }
        return $res;

    }

}
